// pages/place/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        index: -2,
        college: [{
            name: '实验室1',
            id: -1
        },
            {
                name: '实验室2',
                id: 0
            },
            {
                name: '实验室3',
                id: 1
            },
            {
                name: '实验室4',
                id: 2
            }
        ],
        scrollTop: 0,
        scrollH: 0,
        list: [
            {
                name: '通风柜01',
                speed: 0.45,
                light: true,
                humidity: 50,
                height: 35
            }, {
                name: '通风柜02',
                speed: 0.55,
                light: false,
                humidity: 50,
                height: 35
            }, {
                name: '通风柜03',
                speed: 0.65,
                light: false,
                humidity: 50,
                height: 35
            }, {
                name: '通风柜04',
                speed: 0.75,
                light: true,
                humidity: 55,
                height: 65
            }, {
                name: '通风柜05',
                speed: 0.45,
                light: true,
                humidity: 50,
                height: 35
            }
        ]
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this;
        const query = wx.createSelectorQuery()
        query.select('#block0').boundingClientRect()
        query.selectViewport().scrollOffset()
        query.exec(function (res) {
            that.setData({
                scrollH: res[0].top,
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    //监测屏幕滚动
    onPageScroll: function (e) {
        this.setData({
            //scrollTop: parseInt((e.scrollTop) * wx.getSystemInfoSync().pixelRatio),
            scrollTop: parseInt(e.scrollTop)
        })
    },
    //操作获取数据
    tabtapopt(e) {
        var that = this;
        var colleges = that.data.college;
        var collegeCur = e.detail;
        this.setData(
            {
                index: collegeCur
            }
        )
        if (collegeCur == -2) {
            wx.showToast({
                title: '全部',
            })
        } else {
            var names = "";
            colleges.forEach(function (value, index) {
                if (collegeCur == value.id) {
                    names = value.name;
                }
            })

            wx.showToast({
                title: names,
            })
        }
    },
})